home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
msoftapp.zip
/
GENERIC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-01
|
6KB
|
186 lines
// Global variables at the beginning of GENERIC.C
static HINSTANCE hInst; // current instance
static FARPROC lpProcHorzList; // ptr to the HorzList procedure
static FARPROC lpProcAbout; // ptr to the About procedure
static FARPROC lpProcOrgProc; // ptr to the original list box proc
static FARPROC lpProcSubClassProc; // ptr to the subclass list box proc
static UINT uScrollMessage; // custom notification message
/////////////////////////////////////////////////////////////////
// Added to the instance-initialization routine
uScrollMessage = RegisterWindowMessage( "MyScrollNotificationMsg" );
/////////////////////////////////////////////////////////////////
// Replacement for the WM_COMMAND case
case WM_COMMAND: // message: command from application menu
{
switch (wParam)
{
case IDM_HORZLIST:
{
lpProcHorzList = MakeProcInstance(
(FARPROC)HorzListProc, hInst );
lpProcSubClassProc = MakeProcInstance(
(FARPROC)WndListBoxProc, hInst );
DialogBox( hInst, "HorzListBox",
hWnd, lpProcHorzList );
FreeProcInstance( lpProcSubClassProc );
FreeProcInstance( lpProcHorzList );
return 0;
}
case IDM_ABOUT:
{
lpProcAbout = MakeProcInstance( About, hInst );
DialogBox( hInst, "AboutBox", hWnd, lpProcAbout );
FreeProcInstance( lpProcAbout );
return 0;
}
default:
// Let Windows process it
return DefWindowProc( hWnd, message, wParam, lParam );
} // End of switch (wParam)
} // End of case WM_COMMAND:
/////////////////////////////////////////////////////////////////
// Horizontal-Scrolling List Box Dialog Procedure
extern BOOL FAR PASCAL HorzListProc
(
HWND hDlg,
unsigned message,
WORD wParam,
LONG lParam
)
{
auto HWND hWndListBox;
auto char buf[256];
if (message == uScrollMessage)
{
int iMinPos,
iMaxPos,
iCurPos;
hWndListBox = GetDlgItem( hDlg, ID_LIST );
GetScrollRange( hWndListBox, SB_HORZ, &iMinPos, &iMaxPos );
iCurPos = GetScrollPos( hWndListBox, SB_HORZ );
wsprintf( buf, "Min: %d, Cur: %d, Max: %d",
iMinPos, iCurPos, iMaxPos );
SetDlgItemText( hDlg, ID_TEXT, buf );
return 0;
}
switch (message)
{
case WM_INITDIALOG:
{
char c;
// Get the window handle of the list box
hWndListBox = GetDlgItem( hDlg, ID_LIST );
// Grab the original list box window procedure
lpProcOrgProc = (FARPROC)GetWindowLong(
hWndListBox, GWL_WNDPROC );
// ... and replace it with our own!
SetWindowLong( hWndListBox, GWL_WNDPROC,
(LONG)lpProcSubClassProc );
// Initialize the list box with some sample data
for (c = 'A'; c <= 'Z'; c++)
{
// format a string
wsprintf( buf, "%c\tThis is a very long string "
"to test the horizontal scrolling\t%c",
c, c );
// stick the string into the list box
SendMessage( hWndListBox, LB_ADDSTRING, 0,
(LPARAM)(LPSTR)buf );
}
// Enable the horizontal scroll bar
SendMessage( hWndListBox,
LB_SETHORIZONTALEXTENT, 500, 0L );
// Set the horizontal scroll bar range and position
SetScrollRange( hWndListBox, SB_HORZ, 0, 100, FALSE );
SetScrollPos( hWndListBox, SB_HORZ, 0, FALSE );
// Force the display to initialize the display
PostMessage( hDlg, uScrollMessage, wParam, lParam );
return TRUE;
}
case WM_COMMAND:
if (wParam == IDOK
|| wParam == IDCANCEL)
{
// Get the window handle to the list box
hWndListBox = GetDlgItem( hDlg, ID_LIST );
// Reinstall the original list box procedure
SetWindowLong( hWndListBox, GWL_WNDPROC,
(LONG)lpProcOrgProc );
// ... and end the dialog
EndDialog( hDlg, TRUE );
return TRUE;
}
break;
}
return FALSE;
}
/////////////////////////////////////////////////////////////////
// List Box Subclassing Window Procedure.
// This subclass procedure will notify the parent window
// whenever the Horizontal Scroll Bar is scrolled.
extern long FAR PASCAL WndListBoxProc
(
HWND hWnd,
unsigned wMsg,
WORD wParam,
LONG lParam
)
{
switch (wMsg)
{
// When the scroll bar notifies the parent window
// (in this case the list box) of a horizontal
// scroll message, notify the parent of the list
// box, also.
case WM_HSCROLL:
{
HWND hParentWnd;
// Get the handle to the parent of the list box
hParentWnd = GetWindowWord( hWnd, GWW_HWNDPARENT );
// Post a special notification message to it.
PostMessage( hParentWnd, uScrollMessage,
wParam, lParam );
}
}
// Allow all messages to be processed normally by the original
// list box window procedure
return CallWindowProc( lpProcOrgProc, hWnd, wMsg, wParam, lParam );
}